#!/bin/bash

# 定义被移动的 widgets 列表
MOVED_WIDGETS=(
"volume_indicator.dart"
"video_player_ui.dart"
"video_player_widget.dart"
"video_progress_bar.dart"
"video_settings_menu.dart"
"video_upload_ui.dart"
"volume_gesture_area.dart"
"tooltip_bubble.dart"
"translation_button.dart"
"transparent_page_route.dart"
"typing_text.dart"
"vertical_indicator.dart"
"video_controls_overlay.dart"
"subtitle_list_menu.dart"
"subtitle_tracks_menu.dart"
"switchable_view.dart"
"system_resource_display.dart"
"tag_search_widget.dart"
"seek_indicator.dart"
"send_danmaku_dialog.dart"
"settings_hint_text.dart"
"settings_slider.dart"
"speed_boost_indicator.dart"
"splash_screen.dart"
"network_check_dialog.dart"
"playback_rate_menu.dart"
"playlist_menu.dart"
"rating_dialog.dart"
"responsive_container.dart"
"right_edge_hover_menu.dart"
"loading_placeholder.dart"
"media_server_selection_sheet.dart"
"menu_button.dart"
"modern_video_controls.dart"
"jellyfin_media_library_tab.dart"
"jellyfin_media_library_view.dart"
"jellyfin_server_dialog.dart"
"jellyfin_sort_dialog.dart"
"library_management_tab.dart"
"loading_overlay.dart"
"emby_server_dialog.dart"
"episode_select_dialog.dart"
"floating_action_glass_button.dart"
"history_all_modal.dart"
"hover_tooltip_bubble.dart"
"image_assets.dart"
"custom_refresh_indicator.dart"
"custom_scaffold.dart"
"custom_slider.dart"
"danmaku_tracks_menu.dart"
"drag_drop_overlay.dart"
"emby_media_library_view.dart"
"brightness_gesture_area.dart"
"brightness_indicator.dart"
"cached_network_image_widget.dart"
"control_bar_settings_menu.dart"
"countdown_snackbar.dart"
"blur_dialog.dart"
"blur_dropdown.dart"
"blur_login_dialog.dart"
"blur_snackbar.dart"
"bounce_hover_scale.dart"
"base_settings_menu.dart"
"blur_button.dart"
"audio_tracks_menu.dart"
"back_button_widget.dart"
"background_with_blur.dart"
"anime_card.dart"
"anime_info_widget.dart"
"danmaku_settings_menu.dart"
"send_danmaku_button.dart"
"danmaku_list_menu.dart"
"dandanplay_user_activity.dart"
)

# 遍历所有 .dart 文件
find lib -name "*.dart" | while read -r file; do
  # 遍历所有被移动的 widgets
  for widget in "${MOVED_WIDGETS[@]}"; do
    # 构造旧的和新的 import 路径
    OLD_IMPORT_PATH="package:nipaplay/widgets/$widget"
    NEW_IMPORT_PATH="package:nipaplay/themes/nipaplay/widgets/$widget"
    
    # 使用 sed 进行替换
    # 注意：macOS 和 Linux 的 sed 命令有差异，这里使用兼容 macOS 的写法
    sed -i '' "s|'$OLD_IMPORT_PATH'|'$NEW_IMPORT_PATH'|g" "$file"
    sed -i '' "s|\"$OLD_IMPORT_PATH\"|\"$NEW_IMPORT_PATH\"|g" "$file"
  done
done

echo "所有 import 路径已修复完毕。"
